package com.schoolhelper.controller.activity;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hyphenate.easeui.constants.EaseConstant;
import com.schoolhelper.controller.adapter.DetailRecyclerViewDiscussAdapter;
import com.schoolhelper.model.Model;
import com.schoolhelper.model.MyRedissonManager;
import com.schoolhelper.model.YyzExecutors;
import com.schoolhelper.model.adaptermodel.DetailRecyclerViewDiscuss;
import com.schoolhelper.model.dao.okhttp.RefactorRequestUrl;
import com.schoolhelper.model.dao.okhttp.RequestUtil;
import com.schoolhelper.model.entity.Discuss;
import com.schoolhelper.model.entity.Favorite;
import com.schoolhelper.model.entity.Order;
import com.schoolhelper.model.entity.OrderImage;
import com.schoolhelper.model.entity.User;
import com.schoolhelper.model.vo.OrderDiscussVo;
import com.schoolhelper.model.vo.OrderImgVo;
import com.schoolhelper.utils.ImageUtils;
import com.schoolhelper.utils.MyCache;
import com.schoolhelper.utils.RelativeDateFormat;
import com.schoolhelper.model.dao.jsonparse.EasyCodeJsonParser;
import com.schoolhelper.model.dao.jsonparse.JsonParser;
import com.schoolhelper.model.dao.jsonparse.YyzControllerJsonParser;
import com.schoolhelper.utils.constant.Api;
import com.schoolhelper.utils.constant.YyzState;
import com.schoolhelper.utils.constant.YyzApi;


import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;

import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;

import lombok.SneakyThrows;

// yyzTest
public class DetailActivity extends AppCompatActivity {
    OrderImgVo thisOrderImgVo;
    User userOrder;
    User userMyself;
    TextView tvTitle;
    TextView tvDescription;
    TextView tvMoney;
    TextView tvUsername;
    TextView tvCredit;
    TextView tvRelativeDate;
    TextView tvDetailDate;
    ImageView ivOrderState;
    Button btnAcceptOrder;
    Button btnSubmitDiscuss;
    ImageView ivFavourite;

    ImageView ivChat;
    TextView tvChat;

    ImageView ivUser;
    List<ImageView> ivDescriptionList = new ArrayList<ImageView>();
    int ivDescriptionHeight;
    int ivDescriptionWidth;

    Bitmap ivUserImageBitmap;
    Bitmap ivDescriptionImageBitmap;
    Bitmap[] ivDescriptionImageBitmapList = new Bitmap[3];

    Bitmap ivOrderGreenStateImageBitmap;
    Bitmap ivOrderRedStateImageBitmap;

    YyzState myState = YyzState.unset;
    // 所有order
    List<OrderImgVo> orderList;
    // 所有用户信息
    List<User> userList;
    // 所有讨论
    List<OrderDiscussVo> orderDiscussVoList;
    // 设置recycleViewDiscuss
    List<DetailRecyclerViewDiscuss> detailRecyclerViewDiscussList = new ArrayList<>();
    // 当前讨论（带order信息
    OrderDiscussVo thisOrderDiscussVo;
    // 当前页order id
    Long orderId;
    // 我自己的id
    int myselfId;
    RedissonClient redisson;
    volatile RLock lock;
    final Semaphore semaphore = new Semaphore(0);


    public static String lockName = "detail_lock";
    public static final int updateUserIvCode = 100;
    public static final int updateDescriptionIvCode = 200;
    public static final int updateGreenStateIvCode = 300;
    public static final int updateRedStateIvCode = 301;

    public static final String defaultIvDescriptionImageUrl = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcdn.duitang.com%2Fuploads%2Fitem%2F201403%2F21%2F20140321165404_tY5fh.png&refer=http%3A%2F%2Fcdn.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1623503018&t=4bb92835e6b850c51b4ef6c52d863198";
    public static final String defaultIvUserImageUrl = "https://i.loli.net/2021/03/25/aDF6qK3GZBTXhLp.jpg";
    public static final String greenCircleImageUrl = "https://i.loli.net/2021/05/14/3iMPvWnBFNcVOCR.png";
    public static final String redCircleImageUrl = "    https://i.loli.net/2021/05/14/5nCXa6TrW8qu3yQ.png";


    @SneakyThrows
    @RequiresApi(api = Build.VERSION_CODES.Q)
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);


        ivChat = findViewById(R.id.detail_imageView2);
        tvChat = findViewById(R.id.detail_tv_chat);
        ivChat.setOnClickListener(v -> {
            chat();
        });
        tvChat.setOnClickListener(v -> {
            chat();
        });

        synchronized (this) {
            // 连接redis
            new Thread(() -> {
                redisson = MyRedissonManager.getRedisson();
                // 获取锁
                lock = redisson.getLock(lockName);
            }).start();
        }
        //  获取信息
        synchronized (this) {
            getAllInfo();

        }

        //  recyclerview配置
        synchronized (this) {
            setDiscussRecyclerView();
        }

        // 检查信息并弹框提示
        synchronized (this) {
            checkInfo();
            if (myState != YyzState.unsafe) {
                // 更新组件内容
                updateThePage();
                Toast.makeText(this, "数据成功加载", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "数据加载失败，展示默认页面", Toast.LENGTH_SHORT).show();
            }
        }
        synchronized (this) {
            //  accept按钮设置
            btnAcceptOrder = findViewById(R.id.detail_btn_help);
            btnAcceptOrder.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    new Thread(() -> {
                        submitAccept();
                    }).start();

                }
            });


            // discuss按钮设置
            btnSubmitDiscuss = findViewById(R.id.detail_btn_discuss_submit);
            btnSubmitDiscuss.setOnClickListener(new View.OnClickListener() {
                @SneakyThrows
                @Override
                public void onClick(View v) {
                    discussBtnSubmit();
                }
            });

            // detail_btn_favourite按钮设置
            ivFavourite = findViewById(R.id.detail_btn_favourite);
            ivFavourite.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setFavourite();
                }
            });
        }

    }

    public void chat(){
        if (MyCache.read(getApplicationContext(), "userId") == null) {
            runOnUiThread(() -> {
                Toast.makeText(getApplicationContext(), "您需要先登录才能开始聊天", Toast.LENGTH_SHORT).show();
            });
            Intent toLogin = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(toLogin);
        } else {
            Intent intent = new Intent(getApplicationContext(), ChatActivity.class);
            intent.putExtra(EaseConstant.EXTRA_CONVERSATION_ID, userOrder.getPhone());
            intent.putExtra(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE);
            intent.putExtra(EaseConstant.EXTRA_IS_ROAM, true);
            startActivity(intent);
            finish();
        }
    }


    public void setFavourite() {
        if (MyCache.read(getApplicationContext(), "userId") == null) {
            runOnUiThread(() -> {
                Toast.makeText(getApplicationContext(), "您需要先登录才能收藏", Toast.LENGTH_SHORT).show();
            });
            Intent toLogin = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(toLogin);
        } else {
            Model.getInstance().getGlobalThreadPool().execute(() -> {
                synchronized (this) {
                    boolean hasFavourite = false;
                    // 加入到收藏列表
                    // 获取所有收藏信息
                    List<Favorite> favoriteList = RequestUtil.getAll(Api.FAVORITE, Favorite.class);
                    System.out.println(favoriteList);
                    for (Favorite f : favoriteList) {
                        if (f.getUserId() == myselfId && f.getOrderId().equals(orderId)) {
                            Looper.prepare();
                            Toast.makeText(getApplicationContext(), "你已经收藏啦！", Toast.LENGTH_SHORT).show();
                            Looper.loop();
                            hasFavourite = true;
                        }
                    }
                    if (!hasFavourite) {
                        Favorite favorite = new Favorite();
                        favorite.setOrderId(orderId);
                        favorite.setUserId(myselfId);
                        favorite.setFavoriteDatetime(new Date());
                        boolean post = RequestUtil.post(Api.FAVORITE, favorite);
                        if (post) {
                            Looper.prepare();
                            Toast.makeText(getApplicationContext(), "收藏成功，可以到个人中心->收藏查看", Toast.LENGTH_SHORT).show();
                            Looper.loop();
                        }
                    }
                }

            });
        }

    }

    @RequiresApi(api = Build.VERSION_CODES.Q)
    public void discussBtnSubmit() throws ExecutionException, InterruptedException {
        if (MyCache.read(getApplicationContext(), "userId") == null) {
            runOnUiThread(() -> {
                Toast.makeText(getApplicationContext(), "您需要先登录才能评论", Toast.LENGTH_SHORT).show();
            });
            Intent toLogin = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(toLogin);
        } else {
            TextView textView = findViewById(R.id.detail_discuss_et);
            System.out.println(textView.getText());
            if (textView.getText().toString().equals("")) {
                Toast.makeText(getApplicationContext(), "提交不能为空哦", Toast.LENGTH_SHORT).show();
            } else {
                Future<String> post = YyzExecutors.submit(new Callable<String>() {
                    @Override
                    public String call() throws Exception {
                        Discuss discuss = new Discuss();
                        discuss.setOrderId((long) orderId);
                        discuss.setUserId(myselfId);
                        discuss.setDiscussText(textView.getText().toString());
                        discuss.setDiscussDatetime(new Date());

                        return RefactorRequestUrl.getPostResponseJson(Api.BASE_URL,
                                Api.DISCUSS, new HashMap<>(), discuss);
                    }
                });
                String postResponseJson = post.get();
                System.out.println(postResponseJson);
                if (postResponseJson.contains("true")) {
                    Toast.makeText(getApplicationContext(), "发送成功", Toast.LENGTH_SHORT).show();
                }

            }
        }


    }

    @SneakyThrows
    @RequiresApi(api = Build.VERSION_CODES.Q)
    public void initRecyclerViewContentDiscuss() {
        System.out.println("thisOrderDiscussVo");
        System.out.println(thisOrderDiscussVo);
        List<Discuss> discussList = thisOrderDiscussVo.getOrderDiscusses();

        if (discussList != null) {
            for (int i = discussList.size() - 1; i >= 0; i--) {
                Discuss discuss = discussList.get(i);
                DetailRecyclerViewDiscuss detailRecyclerViewDiscuss = discuss.turn2DetailRecyclerViewDiscuss(userList);
                detailRecyclerViewDiscussList.add(detailRecyclerViewDiscuss);
            }
        }


    }

    @SneakyThrows
    private void getAllDiscussListAndSetThisOrderDiscussVo() {
        // 获取所有Discuss
        JsonParser jsonParser = new YyzControllerJsonParser();
        Map<String, String> headers = new HashMap<>();
        Future<List<OrderDiscussVo>> futureOrderDiscussVoList = YyzExecutors.submit(new Callable<List<OrderDiscussVo>>() {
            @Override
            public List<OrderDiscussVo> call() throws Exception {
                return RefactorRequestUrl.postThenGetList(
                        Api.BASE_URL, YyzApi.ORDER_WITH_DISCUSS, headers, null,
                        OrderDiscussVo.class, jsonParser);
            }
        });

        orderDiscussVoList = futureOrderDiscussVoList.get();

        // 设置当前orderDiscussVO
        for (OrderDiscussVo orderDiscussVo : orderDiscussVoList) {
            if (orderDiscussVo.getOrderId() == orderId) {
                thisOrderDiscussVo = orderDiscussVo;
            }
        }
    }

    /**
     * 更新页面
     */
    @SneakyThrows
    @RequiresApi(api = Build.VERSION_CODES.Q)
    public void updateThePage() {
        btnAcceptOrder = findViewById(R.id.detail_btn_help);

        if (thisOrderImgVo.getHelperId() != null) {
            if (thisOrderImgVo.getHelperId() == myselfId) {
                btnAcceptOrder.setText("完成任务");
            } else if (thisOrderImgVo.getHelperId() != myselfId) {
                btnAcceptOrder.setClickable(false);
                btnAcceptOrder.setText("已被领取");

            }
        }
        tvTitle = findViewById(R.id.detail_tv_title);
        tvTitle.setText(thisOrderImgVo.getTitle());

        tvDescription = findViewById(R.id.detail_tv_description);
        tvDescription.setText(thisOrderImgVo.getDescription());
        tvDescription.setMovementMethod(new ScrollingMovementMethod());//设置textview可以滑动
        tvDescription.setScrollbarFadingEnabled(false);//设置scrollbar一直显示

        tvMoney = findViewById(R.id.detail_tv_money);
        tvMoney.setText(MessageFormat.format("￥{0}", thisOrderImgVo.getPrice()));

        tvUsername = findViewById(R.id.detail_tv_username);
        tvUsername.setText(userOrder.getUsername());

        tvCredit = findViewById(R.id.detail_tv_credit);
        tvCredit.setText(MessageFormat.format("积分：{0}", userOrder.getCredit()));

        ivOrderState = findViewById(R.id.detail_iv_order_state);
        Model.getInstance().getGlobalThreadPool().execute(() -> {
            ivOrderGreenStateImageBitmap = ImageUtils.GetLocalOrNetBitmap(greenCircleImageUrl);
            ivOrderRedStateImageBitmap = ImageUtils.GetLocalOrNetBitmap(redCircleImageUrl);
            if (thisOrderImgVo.getStatus().equals("0")) {
                Message message = new Message();
                message.what = updateGreenStateIvCode;
                myHandler.sendMessage(message);
            } else if (thisOrderImgVo.getStatus().equals("1")) {
                Message message = new Message();
                message.what = updateRedStateIvCode;
                myHandler.sendMessage(message);
            }
        });


        ivUser = findViewById(R.id.detail_iv_user);


        Model.getInstance().getGlobalThreadPool().execute(() -> {
            String icUserImageUrl = userOrder.getProfileImg();
            if (icUserImageUrl == null) {
                ivUserImageBitmap = ImageUtils.GetLocalOrNetBitmap(defaultIvUserImageUrl);
            } else {
                ivUserImageBitmap = ImageUtils.GetLocalOrNetBitmap(icUserImageUrl);
            }

            Message message = new Message();
            message.what = updateUserIvCode;
            myHandler.sendMessage(message);
        });

        ImageView view1 = findViewById(R.id.detail_iv_description1);
        ImageView view2 = findViewById(R.id.detail_iv_description2);
        ImageView view3 = findViewById(R.id.detail_iv_description3);

        ivDescriptionHeight = view3.getHeight();
        ivDescriptionWidth = view3.getWidth();

        ivDescriptionList.add(view1);
        ivDescriptionList.add(view2);
        ivDescriptionList.add(view3);


        if (thisOrderImgVo.getOrderImages() != null) {
            List<OrderImage> imgVoOrderImages = thisOrderImgVo.getOrderImages();

            for (int i = 0; i < imgVoOrderImages.size(); i++) {
                int index = i;
                new Thread(() -> {
                    OrderImage orderImage = imgVoOrderImages.get(index);
                    String url = orderImage.getImageUrl();
                    if (url == null) {
                        ivDescriptionImageBitmapList[index] =
                                ImageUtils.GetLocalOrNetBitmap(defaultIvDescriptionImageUrl);
                    } else {
                        ivDescriptionImageBitmapList[index] =
                                ImageUtils.GetLocalOrNetBitmap(url);
                    }
                    Message message = new Message();
                    message.what = updateDescriptionIvCode;
                    message.arg1 = index;
                    myHandler.sendMessage(message);
                }).start();

            }

        } else {
            Toast.makeText(this, "该任务没有图片可以展示", Toast.LENGTH_SHORT).show();
        }


        tvRelativeDate = findViewById(R.id.detail_tv_time_submit);

        tvDetailDate = findViewById(R.id.detail_tv_date_submit2);

        Date postDatetime = thisOrderImgVo.getPostDatetime();

        @SuppressLint("SimpleDateFormat")
        DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        String date = dateFormat.format(postDatetime);
        System.out.println(date);
        tvDetailDate.setText(date);

        String relativeTime = RelativeDateFormat.format(postDatetime);
        tvRelativeDate.setText(relativeTime);


    }


    private void checkInfo() {
        if (thisOrderImgVo == null) {
            Toast.makeText(this, "未获获取到orderImgVo！", Toast.LENGTH_SHORT).show();
            myState = YyzState.unsafe;
        }

        if (userList == null) {
            Toast.makeText(this, "未获获取到UserList！", Toast.LENGTH_SHORT).show();
            myState = YyzState.unsafe;
        }

        if (myState != YyzState.unsafe) {
            for (User u : userList) {
                if (u.getUserId().equals(thisOrderImgVo.getPostUserId())) {
                    userOrder = u;
                }

                if (u.getUserId() == myselfId) {
                    userMyself = u;
                }
            }
        }

        if (userOrder == null) {
            Toast.makeText(this, "未获获取到order的User的信息！", Toast.LENGTH_SHORT).show();
            myState = YyzState.unsafe;
        }

//        if (userMyself == null) {
//            Toast.makeText(this, "未获获取到自己的信息！", Toast.LENGTH_SHORT).show();
//            myState = YyzState.unsafe;
//        }
    }

    private void submitAccept() {
        if (MyCache.read(getApplicationContext(), "userId") == null) {
            runOnUiThread(() -> {
                Toast.makeText(getApplicationContext(), "您需要先登录才能评论", Toast.LENGTH_SHORT).show();
            });
            Intent toLogin = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(toLogin);
        } else {
            Looper.prepare();
            if (btnAcceptOrder.getText() == "完成任务") {
                // 完成任务操作
                Order order = thisOrderImgVo.turnToOrder();
                // 修改状态为已完成
                order.setStatus("2");
                // 修改完成时间
                order.setFinishDatetime(new Date());
                // 提交操作
                RequestUtil.put(Api.ORDER, order);
                Toast.makeText(getApplicationContext(), "提交成功", Toast.LENGTH_SHORT).show();

                return;
            }
            // ------------------------------ 提交前看否能提交,能就提交
            lock.lock();
            // 获取所有order信息
            getAllOrderImgList();
            // 设置当前order
            setThisOrderImgVoInfo();
            // ----------------------------- 如果HelperId为null，说明没人领任务就提交操作
            if (thisOrderImgVo.getHelperId() == null) {
                // 提交操作
                Order order = thisOrderImgVo.turnToOrder();
                // 修改状态为已预定
                order.setStatus("1");
                // 修改接单的人
                order.setHelperId(userMyself.getUserId());
                // 修改接单时间
                order.setHelpDatetime(new Date());
                // 提交操作
                RequestUtil.put(Api.ORDER, order);
            }
            // ---------------------------------------- 验证更新成功
            // 获取所有order信息
            getAllOrderImgList();
            // 设置当前order
            setThisOrderImgVoInfo();
            lock.unlock();
            // 在子线程中直接弹出Toast，会报错，用Looper.prepare();和Looper.loop();

            if (thisOrderImgVo.getHelperId() == myselfId) {
                // -------------------------------------- 输出结果
                Toast.makeText(getApplicationContext(), "成功领取任务，请尽快完成", Toast.LENGTH_SHORT).show();
            } else if (thisOrderImgVo.getHelperId() == null) {
                Toast.makeText(getApplicationContext(), "操作失败，请刷新重试", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "这个任务被别人先领了", Toast.LENGTH_SHORT).show();
            }
            Looper.loop();
        }
    }
    //这个地方的handler最好封装 防止内存泄漏

    @SuppressLint("HandlerLeak")
    private class MyHandler extends Handler {
        @RequiresApi(api = Build.VERSION_CODES.Q)
        @Override
        public void handleMessage(Message msg) {

            if (msg.what == updateUserIvCode) {
                // 设置头像
                ivUser.setImageBitmap(ivUserImageBitmap);
            } else if (msg.what == updateDescriptionIvCode) {
                // 设置order图片
                int ivDescriptionListIndex = msg.arg1;
                ImageView iv = ivDescriptionList.get(ivDescriptionListIndex);
                Bitmap ivDescriptionImageBitmap = ivDescriptionImageBitmapList[ivDescriptionListIndex];
                iv.setImageBitmap(ivDescriptionImageBitmap);

            } else if (msg.what == updateGreenStateIvCode) {
                // 设置绿色状态
                ivOrderState.setImageBitmap(ivOrderGreenStateImageBitmap);
            } else if (msg.what == updateRedStateIvCode) {
                // 设置红色状态
                ivOrderState.setImageBitmap(ivOrderRedStateImageBitmap);
            }


        }
    }

    MyHandler myHandler = new MyHandler();


    // 获取所有order信息
    private void getAllOrderImgList() {
        JsonParser jsonParser = new YyzControllerJsonParser();
        Map<String, String> headers = new HashMap<>();
        orderList = RefactorRequestUrl.postThenGetList(
                Api.BASE_URL, YyzApi.ORDER_WITH_IMG, headers, null,
                OrderImgVo.class, jsonParser);
    }

    private List<User> getAllUser() {

        JsonParser jsonParser = new EasyCodeJsonParser();
        Map<String, String> headers = new HashMap<>();
        userList = RefactorRequestUrl.getThenGetList(
                Api.BASE_URL, Api.USER, headers, null,
                User.class, jsonParser);

        return userList;
    }

    private User getUser(Integer userId) {
        for (User user : userList) {
            if (user.getUserId().equals(userId)) {
                return user;
            }
        }
        return null;
    }

    // 设置当前order信息
    private void setThisOrderImgVoInfo() {
        for (OrderImgVo o : orderList) {
            if (o.getOrderId() == orderId) {
                thisOrderImgVo = o;
                break;
            }
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.Q)
    public void getAllInfo() {
        // 获取当前orderId
        Bundle bundle = this.getIntent().getExtras();
        orderId = bundle.getLong("orderID");
        // 获取当前userId
        if (MyCache.read(getApplicationContext(), "userId") != null) {
            myselfId = Integer.parseInt(MyCache.read(getApplicationContext(), "userId"));
        } else {
            myselfId = 0;
        }
        // 获取所有order信息
        getAllOrderImgList();
        // 设置当前order
        setThisOrderImgVoInfo();
        // 获取所有用户信息
        getAllUser();
        // 获取order的discuss
        getAllDiscussListAndSetThisOrderDiscussVo();
        // 设置RecyclerViewContentDiscuss，这部分必须和recyclerview配置同步
        initRecyclerViewContentDiscuss();
    }

    public void setDiscussRecyclerView() {
        // 获取RecyclerView
        if (detailRecyclerViewDiscussList.size() == 1
                && detailRecyclerViewDiscussList.get(0).getDiscussId() == null) {
            return;
        }

        RecyclerView detailRv = (RecyclerView) findViewById(R.id.detail_discuss_recycle_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);

        detailRv.setLayoutManager(linearLayoutManager);
        System.out.println(detailRecyclerViewDiscussList);
        DetailRecyclerViewDiscussAdapter contentAdapter = new DetailRecyclerViewDiscussAdapter(detailRecyclerViewDiscussList);

        detailRv.setAdapter(contentAdapter);


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyRedissonManager.close();
    }
}